package BF;

public class demo1 {
    public static void main(String[] args) {
        String s1 = "acbbbbaffgbzegkf";
        String s2 = "kf";
        BF(s1,s2);
    }

    public static void BF(String s1, String s2){
        int i = 0;
        int j = 0;
        while (i < s1.length() && j < s2.length()){
            if (s1.charAt(i) == s2.charAt(j)){
                i++;
                j++;
            }else if(s1.charAt(i) != s2.charAt(j)) {
                j = 0;
                i = i-j+1;
            }
        }
        if (i > s1.length()){
            System.out.println("没有找到子串中的位置");
        } else if (j >= s2.length()) {
            System.out.println("找到子串中的位置了 ==> " + (i - j) + " 到 " + (i-1) + " 位置");
        }

    }
}
